package com.icloud.article.boot.controller.app;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.icloud.article.boot.dto.CollectPageDto;
import com.icloud.article.boot.dto.UpvoteDto;
import com.icloud.article.boot.dto.UpvotePageDto;
import com.icloud.article.boot.service.UpvoteService;
import com.icloud.article.boot.vo.ArticleVo;
import com.icloud.common.core.api.CommonResult;
import com.icloud.common.web.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(tags = "App点赞接口")
@RequestMapping("/app/upvote")
@RequiredArgsConstructor
public class AppUpvoteController {

    private final UpvoteService upvoteService;

    @ApiOperation("点赞")
    @PutMapping("")
    public CommonResult<Void> upvote(@Validated @RequestBody UpvoteDto dto){
        upvoteService.upvote(dto.getBusinessType(),dto.getBusinessId());
        return CommonResult.success();
    }

    @ApiOperation("取消点赞")
    @PutMapping("/cancel")
    public CommonResult<Void> cancel(@Validated @RequestBody UpvoteDto dto){
        upvoteService.cancel(dto.getBusinessType(), dto.getBusinessId());
        return CommonResult.success();
    }

    @ApiOperation("点赞列表")
    @PostMapping("/page")
    public CommonResult<IPage<ArticleVo>> page(@Valid @RequestBody UpvotePageDto dto){
        return CommonResult.success(upvoteService.upvotePage(dto));
    }
}
